package applet.admin;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;

import data.CMSRes;
import data.account.admin.AdminAccount;
import applet.admin.components.attendees.CMSAdminAttendeesView;
import applet.admin.components.conference.CMSAdminConferenceView;
import applet.admin.components.events.CMSAdminEventsView;
import applet.view.BaseCMSView;

public class CMSAdminView extends BaseCMSView
{
	public CMSAdminView(AdminAccount admin)
	{
		JPanel view = new JPanel(new BorderLayout());
		view.setBorder(new BevelBorder(BevelBorder.RAISED));
			JPanel topBar = new JPanel(new BorderLayout());
			topBar.setBorder(new EmptyBorder(10, 20, 10, 10));
			topBar.setBackground(CMSRes.Colors.get("Admin Color Medium"));
				
				JLabel usernameLabel = new JLabel("Welcome, Administrator");
				usernameLabel.setFont(usernameLabel.getFont().deriveFont(Font.BOLD));
				topBar.add(usernameLabel, BorderLayout.WEST);
				
				JButton logoutButton = new JButton("Log Out");
				logoutButton.setPreferredSize(new Dimension(150, 30));
				logoutButton.addActionListener(new LogOutListener());
				topBar.add(logoutButton, BorderLayout.EAST);
			
			view.add(topBar, BorderLayout.NORTH);
			
			JPanel tabPanel = new JPanel(new BorderLayout());
			tabPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
			
				JTabbedPane tabs = new JTabbedPane();
				tabs.add("Conference", new JScrollPane(new CMSAdminConferenceView()));
				tabs.add("Events", new JScrollPane(new CMSAdminEventsView()));
				tabs.add("Attendees", new JScrollPane(new CMSAdminAttendeesView()));
				tabPanel.add(tabs, BorderLayout.CENTER);

			view.add(tabPanel, BorderLayout.CENTER);
			
		setView(view);
	}
	
	public void logOut()
	{
		viewController().deferToDefaultView();
	}
	
	private class LogOutListener implements ActionListener {
		@Override public void actionPerformed(ActionEvent e) { logOut(); } }
}